package main

import (
    "os"
    "fmt"
    "log"
    "path"
    "runtime"
)

var logger *log.Logger

func initLog(file string){
    logFile, err := os.OpenFile(file, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0644)
    if err != nil {
        log.Panic("openFile error")
    }
    logger = log.New(logFile, "", log.Ldate | log.Ltime) // | log.Lshortfile)
}

func main(){
    if len(os.Args) < 3 {
        fmt.Println(os.Args[0])
        fmt.Println("get pvr url, workdir")
    }
    fmt.Println(os.Args[1], os.Args[2])
    cpu := runtime.NumCPU()
    runtime.GOMAXPROCS(4)
    os.Chdir(os.Args[2])
    file := path.Join(os.Args[2], "log.out")
    initLog(file)
    logger.Println("Threads:", cpu)
    //get pvr url

    //download
    go Downloader("cctv1", "http://ivi.bupt.edu.cn/hls/cctv1.m3u8")
    //RemoveFiles("cctv")

    //startpvr
    StartPvr(os.Args[2])
}
